#!/usr/bin/env python3

import sys, shutil, subprocess

orig = sys.argv[1]
assert orig.startswith('node_modules/') or orig.startswith('gen/'), orig
new = orig + '.new'
patch = sys.argv[2]
assert patch.startswith('setup/patches') and patch.endswith('.patch'), patch

shutil.copy(orig, new)
subprocess.run(['vi', new])

p = subprocess.run(['diff', '-u', orig, new], capture_output=True, text=True)
p = p.stdout.replace(new, orig)
with open(patch, 'w') as f:
  f.write(p)
